-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attachment api #613
Attachment api #613
Conversation
zenoh/src/publication.rs
Outdated
} | ||
|
||
#[zenoh_macros::unstable] | ||
pub fn attachments_mut(&mut self) -> &mut Option<Attachments> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
attachments
returns Option<&Attachments>
, attachments_mut
should return Option<&mut Attachments>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the mutable accessor, I wanted to give the user the opportunity to straight up remove the attachments, so a reference to the whole option is needed
zenoh/src/query.rs
Outdated
} | ||
|
||
#[zenoh_macros::unstable] | ||
pub fn attachments_mut(&mut self) -> &mut Option<Attachments> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should return Option<&mut Attachments>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
zenoh/src/queryable.rs
Outdated
} | ||
|
||
#[zenoh_macros::unstable] | ||
pub fn attachments_mut(&mut self) -> Option<&mut Option<Attachments>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why double option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above + getting the attachments on replies is fallible since error replies don't have attachments
); 10]; | ||
for (j, backer) in backer.iter_mut().enumerate() { | ||
*backer = ((i * 10 + j).to_le_bytes(), (i * 10 + j).to_be_bytes()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that the Iterator
pattern being used here allows to avoid some extra copy. However, API-wise is very verbose and not-so elegant. Before going any further, I'd like to see a benchmark (e.g. pub/sub throughput) using the assert.insert(...)
and the Iterator
approach. I.e.: I'd like to understand the tradeoff between API usability and performance impact.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to add usage examples, preferably containing both approaches through an iterator and through a map.
self.slices.drain(drain_start..drain_end); | ||
} | ||
fn insert(&mut self, mut at: usize, slice: &[u8]) { | ||
if slice.is_empty() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to check if at
less than buffer size
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed, but computing len
here is a bit expensive... that check can be done by checking for slice_index == usize::MAX
a bit later, adding to the todo list
pub fn iter(&self) -> AttachmentsIterator { | ||
self.into_iter() | ||
} | ||
fn _get(&self, key: &[u8]) -> Option<ZSlice> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we need _get
, if it used only in the get
? (the same for the insert)
Is it some rust syntax sugar?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for code size optimization: it's a rather common pattern when you want to provide a generic input that's immediately converted to a given type, as that conversion doesn't affect the rest of the function's behaviour.
Supposedly, an optimizer could do that for us, but this helps it to do that job by instead considering if it's worth inlining the common section or not, instead of looking for code sections that could be factorized
More thoughts. |
@Mallets agrees with you, I named the type |
but what confuses me is that in rust we will have |
In Rust, it's common practice to use |
examples/examples/z_pub_thr.rs
Outdated
@@ -40,10 +53,28 @@ fn main() { | |||
let mut count: usize = 0; | |||
let mut start = std::time::Instant::now(); | |||
loop { | |||
publisher.put(data.clone()).res().unwrap(); | |||
let attachments = (args.attachments_number != 0).then(|| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to remove the attachments
from the z_pub_thr
and to have it only on the z_pub/z_sub
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
z_sub
example should also show how to use the attachment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine to move it to separate examples.
zenoh/src/publication.rs
Outdated
@@ -117,6 +121,22 @@ impl PutBuilder<'_, '_> { | |||
self.kind = kind; | |||
self | |||
} | |||
|
|||
#[zenoh_macros::unstable] | |||
pub fn attachment(&self) -> Option<&Attachment> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at this more closely. What's the interest of attachment
and attachment_mut
in the PutBuilder
? Shouldn't with_attachment
be enough? It's a builder, so I would expect to be additive for the attachment...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed for builders
zenoh/src/publication.rs
Outdated
|
||
impl<'a> Publication<'a> { | ||
#[zenoh_macros::unstable] | ||
pub fn attachment(&self) -> Option<&Attachment> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar comment as for the PutBuilder
. What's the interest of attachment and attachment_mut in the PutBuilder? Shouldn't with_attachment be enough? It's a builder, so I would expect to be additive for the attachment...
zenoh/src/query.rs
Outdated
@@ -294,6 +306,22 @@ impl<'a, 'b, Handler> GetBuilder<'a, 'b, Handler> { | |||
self | |||
} | |||
|
|||
#[zenoh_macros::unstable] | |||
pub fn attachment(&self) -> Option<&Attachment> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar comment as per other builders. What's the interest of attachment and attachment_mut in the PutBuilder? Shouldn't with_attachment be enough? It's a builder, so I would expect to be additive for the attachment...
zenoh/src/queryable.rs
Outdated
@@ -150,6 +160,36 @@ pub struct ReplyBuilder<'a> { | |||
result: Result<Sample, Value>, | |||
} | |||
|
|||
impl<'a> ReplyBuilder<'a> { | |||
#[zenoh_macros::unstable] | |||
pub fn attachment(&self) -> Option<&Attachment> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar comment as in the other builders... What's the interest of attachment and attachment_mut in the PutBuilder? Shouldn't with_attachment be enough? It's a builder, so I would expect to be additive for the attachment...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, and this spot is especially painful
No description provided.